import { BasicColumn, FormSchema } from "/@/components/Table"
import { render } from "/@/utils/common/renderUtils"
import { UploadBizType } from "/@/enums/uploadEnum"
import { PageEnum } from "/@/enums/pageEnum"
import { DescItem } from "/@/components/Description/index"

export const idpDescSchema: DescItem[] = [
  {
    field: "name",
    label: "名称",
    edit: true,
    span: 2,
  },
  {
    field: "createdAt",
    label: "创建时间",
    span: 2
  },
  {
    field: "description",
    label: "描述",
    span: 4,
  }
]

export const connectTmplDescSchema: DescItem[] = [
  {
    field: "name",
    label: "名称",
    span: 4,
  },
  {
    field: "description",
    label: "描述",
    span: 4,
  }
]



export const columns: BasicColumn[] = [
  {
    title: "图标",
    dataIndex: "logo",
    align: "left",
    width: 50,
    customRender: ({ text }) => {
      return render.renderImagePreview({
        imageList: [{ src: text, width: 45, preview: false }],
      })
    },
  },
  {
    title: "登录模式",
    width: 150,
    align: "left",
    slot: "name",
    dataIndex: "name",
  },
  {
    title: "场景",
    width: 150,
    dataIndex: "sceneNames",
    customRender: ({ text }) => {
      return render.renderTag(text, "green")
    },
  },
  {
    title: "已添加个数",
    width: 80,
    dataIndex: "count",
    customRender: ({ text }) => {
      return render.renderTag([text || 0], text ? "green" : null)
    },
  },
]

export const formSchema: FormSchema[] = [
  {
    field: "id",
    label: "id",
    component: "Input",
    show: false,
  },
  {
    field: "hasClient",
    label: "hasClient",
    component: "Input",
    show: false,
  },
  {
    field: "name",
    label: "名称",
    component: "Input",
    required: true,
  },
  // {
  //   field: 'code',
  //   label: '标识符',
  //   component: 'Input',
  //   required: true
  // },
  {
    field: "grantType",
    label: "授权方式",
    helpMessage: "OAuth客户端与该值进行绑定, 便于进行OAuth2等授权",
    component: "Input",
    required: true,
  },
  {
    field: "configKey",
    label: "配置参数",
    helpMessage: "所有第三方配置参数都去配置中心进行配置, 未配置时, 身份源不会生效",
    component: "Input",
    required: true,
    slot: "configKey",
  },
  {
    label: "场景",
    field: "scenes",
    required: true,
    component: "JDictSelectTag",
    slot: "loginScenes",
  },

  {
    field: "displayName",
    label: "显示名称",
    component: "Input",
  },
  {
    field: "isAskBind",
    label: "询问绑定",
    helpMessage: "当没开启询问绑定时, 若没有绑定任何账号, 则自动创建新账号并进行绑定",
    component: "RadioGroup",
    required: true,
    defaultValue: true,
    componentProps: {
      options: [
        { label: "是", value: true },
        { label: "否", value: false },
      ],
    },
  },

  {
    field: "bindClient",
    label: "关联客户端",
    ifShow: ({ values }) => values.hasClient === "1",
    component: "Input",
    slot: "bindClient",
  },

  {
    label: "图标",
    field: "logo",
    component: "MyImageUpload",
    componentProps: {
      fileMax: 1,
      bizType: UploadBizType.GENERAL_IMAGE,
    },
  },
]

export const formDetailSchema: DescItem[] = [
  {
    field: "name",
    label: "名称",
  },
  {
    field: "grantType",
    label: "授权方式",
  },
  {
    field: "configKey",
    label: "去配置",
    render: (curVal, data) => {
      return render.renderHref({
        url: `${PageEnum.CONFIG_CENTER}?configKey=${curVal}`,
        text: `点我去配置 ${curVal}`
      })
    },
  },

  {
    field: "scenes",
    label: "场景",
    render: (curVal, data) => {
      return render.renderTag(render.renderDict(curVal, "login_scene"), "green")
    },
  },
  {
    field: "isAskBind",
    label: "询问绑定",
    render: (curVal, data) => {
      return render.renderTag(curVal ? '是' : '否', curVal ? "green" : "red")
    },
  },
  {
    field: "logo",
    label: "图标",
    render: (curVal, data) => {
      return render.renderImagePreview({
        imageList: [{ src: curVal, width: 80 }],
      })
    },
  }
]
